/**
 * 
 */
package com.xuetang9.demo.ssm.web;

import java.io.File;
import java.io.IOException;

import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
import org.junit.runner.Request;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
 * @功能
 * @作者 闫健舒
 * @时间 2018年9月14日 上午8:58:55
 * @版本 ver 1.0.0
 */
@RequestMapping("/file")
@Controller
public class FileController {
	
	
	@RequestMapping(path="upload",method=RequestMethod.GET)
	@ResponseBody
	public String upload(MultipartFile file) {
		
		if(file.isEmpty()) {
			System.out.println("上传文件不存在");
			return "无效";
		}
		System.out.println("文件名称"+file.getOriginalFilename());
		System.out.println("文件大小"+file.getSize());
		System.out.println("开始保存");
		
		File saveFile = new File(file.getOriginalFilename());
		
		try {
			file.transferTo(saveFile);
			System.out.println("成功");
		} catch (IllegalStateException | IOException e) {
			System.out.println("失败");
			e.printStackTrace();
		}
		return saveFile.getAbsolutePath();
	}
}
